package com.hp.controller;

import com.hp.context.Config;
import com.hp.entity.Link;
import com.hp.result.DataGridResultInfo;
import com.hp.result.ResultUtil;
import com.hp.result.SubmitResultInfo;
import com.hp.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@Controller
@RequestMapping("/link")
@Controller
public class LinkController {
    @Autowired
    private LinkService linkService;

    @RequestMapping("/querylink_result")
    @ResponseBody
    public DataGridResultInfo querybusiness_result(
            @RequestParam(name = "page", defaultValue = "1") int page,
            @RequestParam(name = "rows", defaultValue = "10") int rows) throws Exception {

        return linkService.findlinkList(page, rows);

    }
    @RequestMapping(value = "/querylink")
    public String querylink(){
        return "link/querylink";//querylink
    }
    /**
     * 去修改页面
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/editlink")
    public String editlink(String id,Map<String,Object> map) throws Exception{
        Link link=linkService.findById(id);
        map.put("link", link);
        return "link/editlink";
    }

    /**
     * 修改链接
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/editlinksubmit",method=RequestMethod.POST)
    @ResponseBody
    public SubmitResultInfo editlinksubmit(Link link) throws Exception{
        linkService.updateLink(link);
        return ResultUtil.createSubmitResult(ResultUtil.createSuccess(Config.MESSAGE, 666, null));
    }
}